Conversation
Use Jaeger for tracing
Add diagnostics for aspdotnet core, middleware, sqlserver, ef core, http clients, and action/result filters for controller actions
There was a problem hiding this comment.
11 file(s) reviewed, 14 comment(s)
Edit PR Review Bot Settings | Greptile
| { | ||
| config.Conventions.Add(new ApiExplorerGroupConvention()); | ||
| config.Conventions.Add(new PublicApiControllersModelConvention()); | ||
| config.Filters.Add(new TracingAttribute()); // Add tracing to controller actions and results |
There was a problem hiding this comment.
style: Adding tracing to all controller actions may introduce performance overhead. Consider selective tracing for critical paths only.
| app.UseSerilog(env, appLifetime, globalSettings); | ||
|
|
||
| // Middleware telemetry | ||
| DiagnosticsHelpers.AddMiddlewareDiagnostics(serviceProvider); |
There was a problem hiding this comment.
logic: Middleware diagnostics may miss some middleware. Ensure comprehensive coverage or implement fallback monitoring.
| ILogger<Startup> logger, | ||
| IServiceProvider serviceProvider) | ||
| { | ||
| IdentityModelEventSource.ShowPII = true; |
There was a problem hiding this comment.
logic: Showing PII in logs could lead to security vulnerabilities. Ensure this is disabled in production environments.
| <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.1-beta.1" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.1-beta.1" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.5.1-beta.1" /> |
There was a problem hiding this comment.
style: These packages are in beta. Consider using stable versions for production, or document the use of beta packages.
| _actionActivity.AddTag("exception", context.Exception.ToString()); | ||
| _actionActivity.AddTag("exceptionStackTrace", context.Exception.StackTrace); |
There was a problem hiding this comment.
style: Be cautious about logging full exception details, as it may expose sensitive information. Consider logging only exception type and message
| if (_activitySource.StartActivity(name, ActivityKind.Server) is Activity activity) | ||
| { | ||
| _activities[name] = activity; | ||
| } |
There was a problem hiding this comment.
logic: This could potentially lead to a memory leak if activities are not properly removed. Consider implementing a cleanup mechanism
| _activities[name].AddTag("exception", exception.ToString()); | ||
| _activities[name].AddTag("exceptionStackTrace", exception.StackTrace); |
There was a problem hiding this comment.
style: Logging full exception details might expose sensitive information. Consider logging only necessary information
| if (name == "Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware" || !_activities.ContainsKey(name)) | ||
| { | ||
| return; | ||
| } |
There was a problem hiding this comment.
logic: The activity might have already been stopped if an exception occurred. Add a check to ensure the activity is still running before stopping it
| if (name == "Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware" || !_activities.ContainsKey(name)) | ||
| { | ||
| return; | ||
| } | ||
| _activities[name].Stop(); | ||
| } |
There was a problem hiding this comment.
style: Consider removing the activity from the dictionary after stopping it to prevent potential memory leaks
| services.AddOpenTelemetry().WithTracing(tracerProviderBuilder => | ||
| tracerProviderBuilder | ||
| .AddSource(diagnosticsConfig.ActivitySource.Name) | ||
| .ConfigureResource(resource => resource | ||
| .AddService(diagnosticsConfig.ServiceName)) | ||
| .AddAspNetCoreInstrumentation() | ||
| .AddSqlClientInstrumentation() | ||
| .AddEntityFrameworkCoreInstrumentation() | ||
| .AddHttpClientInstrumentation() | ||
| .AddOtlpExporter()); |
There was a problem hiding this comment.
style: Consider adding sampling to reduce the volume of telemetry data in production
Type of change
Objective
Adds opentelemetry-based tracing to server projects. Note: tracing is used exclusively as a system profiler to aid in performance optimizations, not intended to trace usage at all. Please let me know if you find some leaked PII in here!
Code changes
TracingAttribute. It works OK, but the library it relies on, Microsoft.Extensions.MiddlewareAnalysis, is poorly documented and seems to be long-forgotten. Sometimes it seems to randomly miss middlewares, but It certainly catches more than if we didn't have it...MiddlewareAnalysisDiagnosticsHelperBefore you submit
dotnet format --verify-no-changes) (required)Greptile Summary
This pull request introduces OpenTelemetry-based tracing to the server projects, focusing on system profiling for performance optimization without tracking user-specific data.
docker-compose.ymlfor distributed tracing analysisTracingAttributeinsrc/Core/Utilities/TracingAttribute.csto wrap controller actions and results with tracing activitiesDiagnosticsConfiginsrc/SharedWeb/Health/DiagnosticsConfig.csto configure ActivitySource based on project nameMiddlewareAnalysisDiagnosticAdapterinsrc/SharedWeb/Health/MiddlewareAnalysisDiagnosticAdapter.csfor middleware execution tracingsrc/Api/Startup.csto integrate tracing and middleware telemetry in the application pipeline